﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AgencyEntityLib.BaseEntity;
using System.Web.UI.WebControls;
using Ecopsy.DataTier;
using AgencyEntityLib.Context;


namespace AgencyEntityLib.BaseEntity
{
    /// <summary>
    /// Визуальное предтавление в гриднике
    /// </summary>
    public class grdConstraction
    {
        protected Constraction _Constraction;

        public grdConstraction(Constraction cons) { _Constraction = cons; }
        public Constraction Constraction { get { return _Constraction; } }
        public string ID { get { return _Constraction.ID; } }
        public virtual string Number { get { return _Constraction.GID; } }
        public virtual string ConstractionTypeName
        {
            get
            {

                return  _Constraction.GetTxtConstractionType();                
                
            }

        }
        public string s_dtCreate { get { return _Constraction.dtCreate.ToShortDateString(); } }
        public string s_dtDestroy
        {
            get
            {
                string s = (_Constraction.dtDestroy.Year == AgencyLib_GlobalConstants.MaxDate.Year ? string.Empty : _Constraction.dtDestroy.ToShortDateString());
                return s;
            }
        }

        public bool Light { get { return _Constraction.bLight; } }
        public bool isCondition { get { return (_Constraction.ConstractionCondition != null); } }
        public bool IsPrizmaVision { get { return _Constraction.IsPrizmaVision; } }

        public string Adress
        {
            get
            {
                return _Constraction.GetTxtAdressProgramm();
            }

        }
        public string FullAdress
        {
            get
            {
                string s = Street;
                return Adress + (s.Length == 0 ? string.Empty : " " + s);
            }
        }

        public virtual string Street
        {
            get
            {
                return  _Constraction.Streets;
            }
        }
        public virtual string ConstractionCondition { get { return _Constraction.GetTxtConstractionCondition(); } }
        public virtual string FullCondition
        {
            get
            {                
                return (ConstractionCondition.Length > 0 ? "Есть" : "Нет");
            }
        }
        public virtual string GeoBinding { get { return _Constraction.GetTxtGeoBinding  (); } }
        public virtual string Location { get { return _Constraction.GetTxtLocation(); } }
        public virtual string Describe { get { return _Constraction.Describe; } }
        public int SideCount { get { return _Constraction.SideList.Count; } }
        public int SurfaceCount
        {
            get
            {
                int r = 0;
                foreach (Side s in _Constraction.SideList)
                {
                    r += s.SurfaceCount;
                }
                return r;
            }
        }

        
        public string sMapXY { get 
        {
            if (_Constraction.MapX == string.Empty) return string.Empty;
            return "X="+_Constraction.MapX + " Y=" + _Constraction.MapY; } 
        }

        public List<Side> SideList { get { return _Constraction.SideList.ToList<Side>(); } }

    }
    
    public static class ConstractionExt
    {
        /// <summary>
        /// Тип конструкции как текст
        /// </summary>

        [ImReportItem(TagName = "ConstractionType")]
        public static string GetTxtConstractionType(this Constraction _Constraction)
        {
            return TreeDictionaryContext.GetPropertyVal(_Constraction.ConstractionType);  
        }
        [ImReportItem(TagName = "AdressProgramm")]
        public static string GetTxtAdressProgramm(this Constraction _Constraction)
        {
            return TreeDictionaryContext.GetPropertyVal(_Constraction.AdressProgramm);
        }

        [ImReportItem(TagName = "ConstractionCondition")]
        public static string GetTxtConstractionCondition(this Constraction _Constraction)
        {
            return TreeDictionaryContext.GetPropertyVal(_Constraction.ConstractionCondition);
        }

        [ImReportItem(TagName = "GeoBining")]
        public static string GetTxtGeoBinding(this Constraction _Constraction)
        {
            return TreeDictionaryContext.GetPropertyVal(_Constraction.GeoBinding);
        }

        [ImReportItem(TagName = "Location")]
        public static string GetTxtLocation(this Constraction _Constraction)
        {
            return TreeDictionaryContext.GetPropertyVal(_Constraction.LocationDescribe);
        }


      

       
    }
}